package com.jxaummd.aquaculture.ui.fragment.first.fun;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;
import com.jackandphantom.joystickview.JoyStickView;
import com.jxaummd.aquaculture.R;
import com.jxaummd.aquaculture.base.BaseBackFragment;
import com.jxaummd.aquaculture.entity.Device;
import com.jxaummd.aquaculture.entity.event.MqttMessageEvent;
import com.jxaummd.aquaculture.util.net.RestClient;
import com.jxaummd.aquaculture.util.net.callback.ISuccess;

import org.greenrobot.eventbus.EventBus;

public class ControlFragment extends BaseBackFragment {

    public static ControlFragment newInstance() {
        Bundle args = new Bundle();
        ControlFragment fragment = new ControlFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_control, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
//        Toolbar toolbar = view.findViewById(R.id.toolbar);
//        toolbar.setTitle("控制设备");
//        initToolbarNav(toolbar);

        JoyStickView joyStickView = view.findViewById(R.id.joy);
        joyStickView.setOnMoveListener(new JoyStickView.OnMoveListener() {
            @Override
            public void onMove(double angle, float strength) {
                System.out.println(angle+"   "+strength+"");
                EventBus.getDefault().post(new MqttMessageEvent("#3|"+(int)angle+"|"+(int)strength+"#","/esp8266/sub840d8ea472b5"));

            }
        });
    }
}
